<?php


/**
 * FCKeditor PHP class
 */
require_once 'WSB/library/WSB/View/Helper/FormRTE/FCKeditor/fckeditor2.6.4/fckeditor.php';


/**
 * Helper to generate a "textarea" element
 *
 * @category   Zend
 * @package    Zend_View
 * @subpackage Helper
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class WSB_View_Helper_FormRTE extends Zend_View_Helper_FormElement
{
    /**
     * Generates a richtext element using FCKeditor.
     *
     *
     * @param string|array $name If a string, the element name.  If an
     * array, all other parameters are ignored, and the array elements
     * are extracted in place of added parameters.
     *
     * @param mixed $value The element value.
     *
     * @param array $attribs Attributes for the element tag.
     *
     * @return string The element XHTML.
     */
    public function formRTE($name = null, $value = null, $attribs = null)
    {
    	if(is_null($name) && is_null($value) && is_null($attribs)) {
    		return $this;
    	}

        $info = $this->_getInfo($name, $value, $attribs);
        extract($info); // name, value, attribs, options, listsep, disable

		$editor = new FCKeditor($name);

		// Setze Membervariabeln
		$editor->BasePath	= 'http://' . WSB_HOST . WSB_URL . 'WSB/library/WSB/View/Helper/FormRTE/FCKeditor/fckeditor2.6.4/' ;
		$editor->ToolbarSet = empty($attribs['ToolbarSet']) ? 'Basic' : $attribs['ToolbarSet'];
		$editor->Width		= empty($attribs['Width']) ? '100%' : $attribs['Width'];
		$editor->Height		= empty($attribs['Height']) ? 500 : $attribs['Height'];
		$editor->Value		= $value;

		// Setze Config Einstellungen
		$editor->Config['BaseHref'] = 'http://' . WSB_HOST . WSB_URL;
		$editor->Config['CustomConfigurationsPath'] = WSB_URL . 'WSB/library/WSB/View/Helper/FormRTE/FCKeditor/config.js';
		$editor->Config['SkinPath'] = 'http://' . WSB_HOST . WSB_URL . 'WSB/library/WSB/View/Helper/FormRTE/FCKeditor/fckeditor2.6.4/editor/skins/silver/';

		return $editor->createHtml();

    }

    /**
     * @return string
     */
	public function getEditorJsApi()
	{
		return '
			var oEditor = window.parent.InnerDialogLoaded() ;
			// Diese Funktion wird in verschiedenen Situation genutzt
			// Normal geoeffnetes Popup, Popup geoeffnet vom FCKeditor, usw.
			function insertHtml(html) {
				oEditor.FCK.InsertHtml( html ) ;
				//window.top.close();
				window.parent.Cancel();
			}
		';
	}

}
